package dto

import (
	"danmu/common"
	"danmu/model"
	"time"
)

type AnnounceDto struct {
	Title   string `json:"title"`
	Content string `json:"content"`
	Status  int    `json:"status"`
	Url     string `json:"url"`
	Date time.Time `json:"date"`
}

type AnnounceListDto struct {
	Aid     uint   `json:"aid"`
	Title   string `json:"title"`
	Content string `json:"content"`
	Url     string `json:"url"`
	Date    time.Time `json:"date"`
}

func ToAnnounceDto(announce []model.AnnounceUser) []AnnounceDto {
	DB := common.GetDB()
	newAnnounce := make([]AnnounceDto, len(announce))
	for i := 0; i < len(announce); i++ {
		var AnnounceContent = model.Announce{}
		//查询公告信息
		DB.First(&AnnounceContent, announce[i].Aid)
		newAnnounce[i].Title = AnnounceContent.Title
		newAnnounce[i].Content = AnnounceContent.Content
		newAnnounce[i].Url = AnnounceContent.Url
		newAnnounce[i].Status = announce[i].Status
		newAnnounce[i].Date = AnnounceContent.UpdatedAt
	}
	return newAnnounce
}

func ToAnnounceListDto(announce []model.Announce) []AnnounceListDto {
	newAnnounceList := make([]AnnounceListDto, len(announce))
	for i:=0;i<len(announce);i++{
		newAnnounceList[i].Aid = announce[i].ID
		newAnnounceList[i].Title = announce[i].Title
		newAnnounceList[i].Content = announce[i].Content
		newAnnounceList[i].Url = announce[i].Url
		newAnnounceList[i].Date = announce[i].UpdatedAt
	}
	return newAnnounceList
}

